package org.eminem.elasticsearch;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

/**
 * ES Client Class
 */
public class ESClient {

    private static Client client;

    @SuppressWarnings("resource")
    public static synchronized Client getEsClient(String clusterName,String host, int port) throws Exception {
        if(null == client){
            Settings settings = ImmutableSettings.settingsBuilder()
                    .put("cluster.name", clusterName).build();
            client = new TransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(
                            host, port));
        }
        return client;
    }
}
